from manim import *



class math1(MovingCameraScene):
    def construct(self):
        self.camera.background_color = BLACK  # 设置背景颜色
        self.camera.frame_width = 100  # 设置边框宽度
        self.camera.frame_height = 60  # 设置边框高度
        self.camera.pixel_height = 1080  # 设置像素高度
        self.camera.pixel_width = 1920  # 设置像素宽度
        self.camera.center = ORIGIN  # 设置中心点位置
        self.camera.scale_factor = 1.0  # 设置缩放因子
        #设置横线
        for i in range(60*2+1):       
            dot1=Dot([-500,5*(i-60),0]).set_opacity(0.5)
            dot2=Dot([500,5*(i-60),0]).set_opacity(0.5)
            if i==6:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
                
            else:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
               
            self.add(dot1,dot2,line1)
        #设置竖线
        for i in range(100*2+1):        
            dot3=Dot([(i-100)*5,-300,0]).set_opacity(0.5)
            dot4=Dot([(i-100)*5,300,0]).set_opacity(0.5)
            if i==10:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
                
            else:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
            self.add(dot3,dot4,line2)
        #设置三个点
        dot1 = Dot(radius=1, color=RED)  
        dot1.move_to([-47.5,27.5,0]) 
        dot2 = Dot(radius=1, color=YELLOW)  
        dot2.move_to([-42.5,27.5,0])  
        dot3 = Dot(radius=1, color=GREEN)  
        dot3.move_to([-37.5,27.5,0])
        #镜头跟进效果 
        self.camera.frame.save_state()
        self.play(self.camera.frame.animate.scale(1).move_to([0,0,0]))
        
        #题目出现
       
        text1 = Tex(r"\text{(2020年)设函数}$f\left( x\right) $\text{满足}$f''\left( x\right) +af'\left( x\right) +f\left( x\right) =0( a > 0) $"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,25,0])
        text10 = Tex(r"\text{,且}$f\left( 0\right) =m,f'\left( 0\right) =n$\text{,则}$\int _{0}^{+\infty }f\left( x\right) dx=$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,20,0])
      





        
        
        
        self.play(Create(text1),Create(text10))
        #镜头拉回
          #分析文本
        #text100=MarkupText("<b><i>分析/解：</i></b>",color=PINK).scale(5.0).move_to([-38,12.5,0])
        self.play(FadeIn(dot1),run_time=0.1)
        self.play(FadeIn(dot2),run_time=0.1)
        self.play(FadeIn(dot3),run_time=0.1)
        #题目向上移动
        rectangle=Rectangle(color=BLUE,fill_opacity=0.0,width=20,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle.move_to([15, 20, 0])
        self.play(Create(rectangle))
        text2 = Tex(r"\text{求}$f\left( x\right) $",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,3,0])
        text3 = Tex(r"\text{计算}$\int ^{+\infty }_{0}f\left( x\right) dx$",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,-15,0])

        arrow = Arrow(start=[10,17,0],end=[0,7,0],color=RED
                       , stroke_width=20, tip_length=1)

        self.play(GrowArrow(arrow))
        self.play(Create(text2))





        arrow1 = Arrow(start=[0,0,0],end=[0,-10,0],color=RED
                       , stroke_width=20, tip_length=1)

        self.play(GrowArrow(arrow1))
        self.play(Create(text3))
        text4 = Tex(r"\text{解微分方程}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-6,12,0])
        self.play(Create(text4))
        text5 = Tex(r"\text{求积分}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-6,-5,0])
        #半透明矩阵扩展
        rectangle4=Rectangle(color=BLUE,fill_opacity=0.5,width=1,height=2.8
                            ,stroke_color=YELLOW,stroke_width=0).move_to([11,25,0])
        self.play(
            rectangle4.animate.stretch(31.0,dim=0)
        )

        self.play(Create(text5))

        text6 = Tex(r"$\lambda ^{2}+a\lambda +1=0$",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-35,10,0])
        self.play(
            
            ReplacementTransform(rectangle4,text6)
            
        )
        text7 = Tex(r"$\Delta =a^{2}-4$",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-35,5,0])
        self.play(Create(text7))
        text8 = Tex(r"$>0,$",color=PURE_GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-41,0,0])
        self.play(Create(text8))
        text9 = Tex(r"$=0,$",color=PURE_GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-35,0,0])
        self.play(Create(text9))
        text10 = Tex(r"$<0$",color=PURE_GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-29,0,0])
        self.play(Create(text10))

        arrow2 = Arrow(start=[-35,-3,0],end=[-35,-13,0],color=RED
                       , stroke_width=20, tip_length=1)

        self.play(GrowArrow(arrow2))

        text11 = Tex(r"$f\left( x\right) $\text{有三种可能}",color=PURE_RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-35,-17,0])
        self.play(Create(text11))















        arrow3 = Arrow(start=[20,17,0],end=[30,7,0],color=RED
                       , stroke_width=20, tip_length=1)

        #self.play(GrowArrow(arrow3),FadeOut(text11,arrow2,text10,text9,text8,text7,text6))
        self.play(GrowArrow(arrow3))
        text12 = Tex(r"\text{直接计算}$\int ^{+\infty }_{0}f\left( x\right) dx$",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([30,4,0])
        self.play(Create(text12))

        #半透明矩阵扩展
        rectangle4=Rectangle(color=BLUE,fill_opacity=0.5,width=1,height=2.8
                            ,stroke_color=YELLOW,stroke_width=0).move_to([11,25,0])
        self.play(
            rectangle4.animate.stretch(31.0,dim=0)
        )
        
        text16 = Tex(r"$\int _{0}^{+\infty }f''\left( x\right) dx+a\int _{0}^{+\infty }f'\left( x\right) dx+\int _{0}^{+\infty }f\left( x\right) dx=0$",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([35,0,0])
        self.play(
            self.camera.frame.animate.scale(1.2).move_to([10,0,0]),
            ReplacementTransform(rectangle4,text16)
            
        )
        text17 = Tex(r"$\left[ f'\left( +\infty \right) -f'\left( 0\right) \right] +a\left[ f\left( +\infty \right) -f\left( 0\right) \right] +\int _{0}^{+\infty }f\left( x\right) dx=0$",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([35,-5,0])
        self.play(Create(text17))
        self.play(FadeOut(text11,arrow2,text10,text9,text8,text7))
        arrow4 = Arrow(start=[-35,7,0],end=[-35,0,0],color=PURE_GREEN
                       , stroke_width=20, tip_length=1)

        
        self.play(GrowArrow(arrow4))
        text18 = Tex(r"$\lambda _{1}+\lambda _{2}=-a <0$",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-35,-3,0])
        text19 = Tex(r"$\lambda _{1}\lambda _{2}=1 >0$",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-35,-6,0])
        self.play(Create(text18))
        self.play(Create(text19))
        arrow5 = Arrow(start=[-35,-10,0],end=[-35,-17,0],color=PURE_GREEN
                       , stroke_width=20, tip_length=1)

        
        self.play(GrowArrow(arrow5))

        text20 = Tex(r"$\lambda _{1},\lambda _{2} <0$",color=PURE_RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-35,-20,0])
        self.play(Create(text20),self.camera.frame.animate.scale(1).move_to([10,-5,0]))
        

        text130 = Tex(r"$\left\{\begin{matrix}\Delta  >0 \Rightarrow & \lambda _{1}\neq \lambda _{2} & \Rightarrow\\\Delta  =0 \Rightarrow & \lambda _{1}=\lambda _{2} & \Rightarrow\\\Delta  <0\Rightarrow & \lambda _{1,2}=\alpha +\beta i &\Rightarrow\end{matrix}\right.$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-30,-30,0])
        self.play(Create(text130))
        text140 = Tex(r"$y=c_{1}e^{-\lambda _{1}x}+c_{2}e^{-\lambda _{2}x}$",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([5,-27,0])
        text150 = Tex(r"$y=\left( c_{1}+c_{2}x\right) e^{\lambda _{1}x}$",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([5,-30,0])
        text160 = Tex(r"$y=e^{\alpha x}\left[ c_{1}\cos \beta x+c_{2}\sin \beta x\right] $",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([5,-33,0])
        self.play(Create(text140),Create(text150),Create(text160))
        text170 = Tex(r"$\alpha =\dfrac{\lambda _{1}+\lambda _{2}}{2} <0$",color=PURE_RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([40,-33,0])
        self.play(Create(text170))



        text21 = Tex(r"$0$",color=PURE_RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([7,-10,0])
        text22 = Tex(r"$0$",color=PURE_RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([33,-10,0])
        self.play(Create(text21),Create(text22))
        text23 = Tex(r"$n$",color=PURE_GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([17,-10,0])
        text24 = Tex(r"$m$",color=PURE_GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([43,-10,0])
        self.play(Create(text23),Create(text24))


        text25 = Tex(r"$n+am$",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([55,-10,0])
        self.play(Create(text25))

        self.wait()